package vpc.ext.stacksize;

import java.io.PrintStream;
import java.util.*;

import vpc.ext.stacksize.util.CycleException;

public class Edge {

	// ************** DATA ******************
	/* The Parent node of the Edge */
	public Node parent;

	/* The Child node of the Edge */
	public Node child;

	/* Internal String representation of the Edge */
	public String id;

	/* Weight of the edge */
	public long weight;

	// **************** CONSTRUCTORS *************
	
	public Edge(Node parent, Node child, long weight) {
		if (parent == null) {
			throw new java.lang.NullPointerException(
					"Parent argument to Edge constructor is null");
		}
		if (child == null) {
			throw new java.lang.NullPointerException(
					"Child argument to Edge constructor is null");
		}

		this.parent = parent;
		this.child = child;
		this.weight = weight;

		this.id = "(parent=" + parent.name + " ,child=" + child.name
				+ " ,weight=" + this.weight + ")";

	}

	// ***************** OBJECT METHODS ****************
	
	public boolean equals(Edge e) {
		return this.id.equals(e.id);
	}

	public Node find(String searchName, Set<Node> nodesSeen) {
		return child.find(searchName, nodesSeen);
	}

	public Node find(int searchId, Set<Node> nodesSeen) {
		return child.find(searchId, nodesSeen);
	}

	public void changeRoot(Node root, Set<String> nodesSeen) {
		child.changeRoot(root, nodesSeen);
	}

	public String toString() {
		return this.id;
	}

	public void printGraph(PrintStream o, Set<Node> nodesSeen) {
		this.child.printGraph(o, nodesSeen);
	}

	public int getMaxPush(Set<Node> nodesSeen) throws CycleException {
		return child.getMaxPush(nodesSeen);
	}

}
